//公共场所
import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { getGisEntityList } from '@gis/lib/api';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';

const typeCodeEnum = {
  '6_19': 'fuwuz', //服务站
  '6_18': 'changyi', //休息长椅
  '6_17': 'wc', //公共厕所
  '6_16': 'chewei', //停车位
};

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = typeCodeEnum[data.category];
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getLabel() {
    const label = super.getLabel();
    label.content = `
      <div class="marker_label">
        <p class="marker_label__name">${this.data.name}</p>
      </div>`;
    return label;
  }
  onClick() {}
}

export default class Ggcsuo extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      area_code: area_code,
      type_code: "'6_19','6_18','6_17','6_16'",
    };
    const data = await handleCommonRes(getGisEntityList, params);
    return data.map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
